#include <QtCore/QCoreApplication>

#include <math.h>
#include <iostream>

long P(long n, long r);
long C(long n, long r);
long pi(long n);

void P_20();
using namespace std;



int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::cout<<"P(20,20)="<<P(20,20)<<std::endl;
    std::cout<<"C(49,5)="<<C(49,5)<<std::endl;
    std::cout<<"P(13,5)="<<P(13,5)<<std::endl;
    std::cout<<"C(13,5)="<<C(13,5)<<std::endl;

    P_20();
    return a.exec();
}

void P_20()
{
    long part1=0;
    long part2=0;
    long part3=0;
    //
    for(int i=1;i<=6;i++)
    {
        part1=part1+C(7,i)*C(5,6-i);
    }
    cout<<"part1="<<part1<<endl;
    for(int i=1;i<=5;i++)
    {
        part2=part2+C(13,i)*C(4,5-i);
    }
    cout<<"part2="<<part2<<endl;
    for(int i=1;i<=3;i++)
    {
        part3=part3+C(18,i)*C(2,3-i);
    }
    cout<<"part3="<<part3<<endl;
    cout<<"P_20="<<part1*part2*part3<<endl;
}


long pi(long n)
{
    long rs=1;
    if(n<1)
    {
        return 1;
    }
    else
    {
        for(long i=1;i<=n;i++)
        {
            rs=rs*i;
        }
        return rs;
    }
}

long P(long n,long r)
{
    long rs=1;
    for(long i=n;i>(n-r);i--)
    {
        rs=rs*i;
    }
    return rs;
}

long C(long n,long r)
{
    long rs=1;
    if(r<1)return 1;
    rs=P(n,r)/pi(r);
    return rs;
}
